<?php
/**
* 
*/
class Tourism_order_barter_model extends CI_Model
{
	
	private $_table  = 'tourism_order_barter';
	private $_table1 = 'tourism_order_product';
	private $_table2 = 'user';

	/**
	 * 商品换货总数
	 */
	public function tourismBartchTotal($param)
	{
		$this->db->select('tourism_order_barter.barter_id');
        $this->db->from($this->_table.' as tourism_order_barter');
        $this->db->join($this->_table1.' as tourism_order_product','tourism_order_product.order_product_id = tourism_order_barter.order_product_id');
        $this->db->join($this->_table2.' as user','tourism_order_barter.seller_uid = user.uid');
        $this->db->where('tourism_order_barter.uid', $param['uid']);
        return $this->db->count_all_results();
	}

	/**
	 * 商品换货列表
	 */
	public function tourismBartchList($param, $count, $start = 0)
	{
		$this->db->select('tourism_order_barter.barter_id,existing,tourism_order_barter.user_name,
						tourism_order_barter.status,tourism_order_barter.flag,tourism_order_barter.number,
                        tourism_order_product.goods_name,attribute_value,goods_image,shop_price,pay_amount,
                        user.alias_name,counter_fee');
        $this->db->from($this->_table.' as tourism_order_barter');
        $this->db->join($this->_table1.' as tourism_order_product','tourism_order_product.order_product_id = tourism_order_barter.order_product_id');
        $this->db->join($this->_table2.' as user','tourism_order_barter.seller_uid = user.uid');
        $this->db->where('tourism_order_barter.uid', $param['uid']);
        $this->db->order_by('barter_id', 'DESC');
        $this->db->limit($count, $start);
        return $this->db->get();
	}

	/**
	 * 查找换货产品
	 */
	public function findProductInfo($barterId)
	{
		$this->db->select('barter_id, existing, tourism_order_barter.number, user_name, cellphone, counter_fee, status, logistics_company, 
							logistics, images, flag, refund_content, reject_content, tourism_order_barter.created_at, tourism_order_barter.verify_time,
							pay_amount');
		$this->db->from($this->_table.' as tourism_order_barter');
        $this->db->join($this->_table1.' as tourism_order_product','tourism_order_product.order_product_id = tourism_order_barter.order_product_id');
        $this->db->where('tourism_order_barter.barter_id', $barterId);
        $this->db->limit(1);
        return $this->db->get();
	}

}